

export const moduleLogin = {
  state: {
      //存储当前已经发起的promise请求容器
      userInfo:{}
  },
  getters: {
      getUser(state){
        //console.log(state.userInfo)
        if(!state.userInfo.accountId){
          state.userInfo = JSON.parse(sessionStorage.getItem('userinfo') || '{}')
          //console.log('get from session',JSON.parse(sessionStorage.getItem('userinfo')))
        }
        //console.log('get local userInfo--s',state.userInfo)
        return state.userInfo;
      }
  },
  mutations:{
    login(state,userInfo){
      //console.log('login--userinfo',userInfo)
      state.userInfo = userInfo
      //console.log('login==userinfo',userInfo)
      sessionStorage.setItem('userinfo',JSON.stringify(userInfo))
      var json = JSON.parse(localStorage.getItem("userinfo") || '{}')
      //console.log('json',json)
    },
    logout(state){
      //console.log('out--',state)
      state.userInfo = {}
      //console.log('out==',state)
      sessionStorage.removeItem('userinfo');
    }
  },
  actions: {
    login(context){
      context.commit('login')
    },
      
  }
}